//
//  SEGFindDictionaryInfoManagr.m
//  Commom
//
//  Created by 山刘 on 2019/4/1.
//  Copyright © 2019年 山刘. All rights reserved.
//

#import "SEGFindDictionaryInfoManagr.h"
#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif

#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

static id _findDictionaryInfoManagr;
static dispatch_once_t onceToken;

@implementation SEGFindDictionaryInfoManagr
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _findDictionaryInfoManagr = [[self alloc] init];
    });
    return _findDictionaryInfoManagr;
}

+(void)destroyResource{
    onceToken = 0;
    _findDictionaryInfoManagr = nil;
}

// 查找字典参数
-(void)requestDictionaryInfoByCode:(NSString*)code completed:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))completed{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:code forKey:@"code"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/common/findDictionaryInfo.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        
        if (!isSuccessed || result == nil) {
            completed(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        NSDictionary* dict = [result valueForKey:@"data"];
        self.dataDictionary = [SEGDictionaryInfoModel yy_modelWithJSON:dict];
        completed(YES,result,codeType,error.localizedDescription);
        return;
    }];
}

-(SEGDictionaryInfoModel *)dataDictionary{
    if (!_dataDictionary) {
        _dataDictionary = [[SEGDictionaryInfoModel alloc]init];
    }
    return _dataDictionary;
}


@end
